<?php
class renderer_relation_has_many extends renderer_base
{

    public function searchRender($fObject)
    {
        $coll = $fObject->getOptions();
        $this->lead->viewer->coll = $coll;
        
        if($fObject->getConfig('render_as') == 'link')
        {
            return 'nuller';
        }
        elseif($fObject->getConfig('render_as') == 'select')
        {
            DatatypeRenderer::getInstance()->stackOwner($fObject->getName());
            
            
            $this->lead->viewer->fObject = $fObject;
    		$this->lead->viewer->fRenderer = $this;
            
            $items = array();
            foreach($coll as $key => $item)
            {
                $items[$item->edoid] = $fObject->resolveTags($item, $fObject->getConfig('display'));
            }
            
            $this->lead->viewer->items = $items;
    
            
                   
            $tpl = $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/search_select.tpl");       
            DatatypeRenderer::getInstance()->unStackOwner();
            return $tpl;
                
        }
       

    }

    

    
    
    public function editRender(Datatype_relation_has_many $fObject)
    {
  		$this->lead->viewer->fObject = $fObject;
		$this->lead->viewer->fRenderer = $this;
        
        if($fObject->getConfig('render_as') == 'dropdown')
        {
            $selected = $fObject->getValue()->getKeys();
            $options = $fObject->getOptions();
            
            $this->lead->viewer->selected = $selected;
            $this->lead->viewer->options = $options;
                           
            return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/edit_dropdown.tpl");       

        }
	    else 
	    {	
			
           	if($fObject->getOwner()->isFetched())
           	{
    		    $coll = $fObject->getValue();
        		$this->lead->viewer->collection = $coll;
	          	return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/link_to_relation.tpl");       
               
           	}
		}
		
       
    }
    
    
    public function viewRender(Datatype_relation_has_many $fObject)
    {
        $coll = $fObject->getValue();

        $this->lead->viewer->fObject = $fObject;
		$this->lead->viewer->fRenderer = $this;
        
        $items = array();
        foreach($coll as $item)
        {
            $items[] = $fObject->resolveTags($item, $fObject->getConfig('display'));
        }
        
        $this->lead->viewer->items = $items;
                        
        return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/view_list_all.tpl");       
                             
           
        
    }
    
    
}